package com.lanou.projecta.news.game;

import android.content.Context;
import android.graphics.Bitmap;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.android.volley.RequestQueue;
import com.android.volley.toolbox.ImageLoader;
import com.android.volley.toolbox.NetworkImageView;
import com.android.volley.toolbox.Volley;
import com.lanou.projecta.R;

import java.util.List;

/**
 * Created by dllo on 16/1/23.
 */
public class GameAdapter extends BaseAdapter{
    private List<GameBase.T1348654151579Entity> base;
    private Context context;
    private RequestQueue queue;

    public GameAdapter(List<GameBase.T1348654151579Entity> base, Context context) {
        queue = Volley.newRequestQueue(context);
        this.base = base;
        this.context = context;
    }
    public void getImage(NetworkImageView imageView, String url) {
        final ImageLoader imageLoader = new ImageLoader(queue, new ImageLoader.ImageCache() {
            @Override
            public Bitmap getBitmap(String url) {
                return null;
            }

            @Override
            public void putBitmap(String url, Bitmap bitmap) {
            }
        });
        imageView.setImageUrl(url, imageLoader);

    }

    @Override
    public int getCount() {
        if (base!=null){
        return base.size();}
        else {
            return 0;
        }
    }

    @Override
    public Object getItem(int i) {
        if (base!=null){
        return base.get(i);}
        else {
            return null;
        }
    }

    @Override
    public long getItemId(int i) {
        if (base!=null){
        return i;}
        else {
            return 0;
        }
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        String url = null;
        if (base!=null){
            url = base.get(i).getImgsrc();
        }
        Handler1 handler1 = null;
        view = LayoutInflater.from(context).inflate(R.layout.game_item,null);
        handler1 = new Handler1();
        handler1.title = (TextView) view.findViewById(R.id.game_title);
        handler1.imageView = (NetworkImageView) view.findViewById(R.id.game_img);
    view.setTag(handler1);
        if (base!=null){
            handler1.title.setText(base.get(i).getTitle());
             getImage(handler1.imageView,url);


        }

        return view;
    }
    class Handler1{
        NetworkImageView imageView;
        TextView title;
    }
}
